package logic

import (
	"cart_srv/cartsrv"
	"cart_srv/internal/svc"
	"cart_srv/models/redis"
	"context"
	"fmt"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListCartLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewListCartLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListCartLogic {
	return &ListCartLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ListCartLogic) ListCart(in *cartsrv.ListCartRequest) (*cartsrv.ListCartResponse, error) {
	// todo: add your logic here and delete this line

	cart, err := redis.ListCart(int(in.UserId))
	if err != nil {
		return nil, err
	}
	fmt.Println(cart)
	return &cartsrv.ListCartResponse{List: cart}, nil
}
